package com.zh.freechat.domain.notice;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.UUID;

/**
 * 推送消息
 * @author ZH
 * @date 16:15 2022/2/22
 */
@Getter
@Setter
public abstract class NoticeMessage implements Cloneable, Serializable {
    /**
     * 消息的接收者
     */
    protected String id;
    protected String receiver;
    /**
     * 消息是不是旧的
     */
    protected boolean stale;
    /**
     * 消息的推送channel
     */
    protected SSEEventType channel;

    protected NoticeMessage(){
        this.id = "sse_"+UUID.randomUUID().toString().substring(24);
    }

    protected NoticeMessage(SSEEventType channel,String receiver) {
        this();
        this.channel = channel;
        this.receiver = receiver;
    }

    public String channelName(){
        return channel.name();
    }

    @Override
    public NoticeMessage clone() {
        try {
            return (NoticeMessage) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
    }

}
